Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beacon search endpoint #402

Merged
merged 14 commits into from
May 17, 2023
Merged

Beacon search endpoint #402

merged 14 commits into from
May 17, 2023

Conversation

gsfk
Copy link
Member

@gsfk gsfk commented May 15, 2023

Create a new katsu endpoint /api/beacon_search, an uncensored equivalent to the bento_public search endpoint /api/public. Returns a full list of matching individual ids rather than censored counts, so that beacon can compute the intersection of results with other searches (in particular for variants). Beacon instead of katsu will apply censorship in this case.

This allows beacon to use katsu's config for search, which gets us:

  1. configurable search, only specific searches are permitted, and
  2. fast extra properties seach, currently not available elsewhere in katsu

@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Merging #402 (bcb4f01) into develop (58dab0a) will increase coverage by 0.08%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #402      +/-   ##
===========================================
+ Coverage    85.43%   85.52%   +0.08%     
===========================================
  Files          127      127              
  Lines         4869     4897      +28     
  Branches       651      657       +6     
===========================================
+ Hits          4160     4188      +28     
+ Misses         536      535       -1     
- Partials       173      174       +1     
Impacted Files Coverage Δ
chord_metadata_service/restapi/urls.py 100.00% <ø> (ø)
chord_metadata_service/patients/api_views.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

davidlougheed

This comment was marked as outdated.

@davidlougheed davidlougheed self-requested a review May 15, 2023 19:30
Copy link
Member

@davidlougheed davidlougheed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor code style things. other than that it looks good to me

search_conf = settings.CONFIG_PUBLIC["search"]
field_conf = settings.CONFIG_PUBLIC["fields"]
queryable_fields = {
f"{f}": field_conf[f] for section in search_conf for f in section["fields"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is a needless format string - it can just be f:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh noes! You want me to pay attention to the code I'm copypasting? 😭

(fixed)

response = self.client.get('/api/beacon_search?birdwatcher=yes')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_obj = response.json()
self.assertEqual(response_obj["code"], 400)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert equal to status.HTTP_400_BAD_REQUEST instead (for these 3 tests)

Copy link
Member Author

@gsfk gsfk May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just copies of the old tests, which, yeah, are a bit weird. Changed the response to 400 and updated the tests.


def get(self, request, *args, **kwargs):
if not settings.CONFIG_PUBLIC:
return Response(settings.NO_PUBLIC_DATA_AVAILABLE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be a 404 instead of a 200? fine to leave as-is for consistency with bento public responses but generally i think in API design it's good to put as much meaning in the status code as possible

Copy link
Member Author

@gsfk gsfk May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was a straight copypaste of the bento_public code, and it struck me as odd also. I won't break the old code, but I'll change the beacon responses to 400 / bad request. (even for missing config, arguably still 400 rather than 404)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i think of 400s more meaning something is wrong with the request... if the client request is good, I still think this should be a 404 (or maybe a 500 if we treat it as a configuration error)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay, I actually re-read the documentation for 404 and this sounds reasonable ("missing resource"). 204 (No content) is also possible but probably a little obscure. I'll change it to 404.

@gsfk gsfk requested a review from davidlougheed May 17, 2023 01:33
@davidlougheed davidlougheed changed the title Beacon changes for bento_public search endpoint Beacon search endpoint May 17, 2023
Copy link
Member

@davidlougheed davidlougheed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@gsfk gsfk merged commit 08d8e87 into develop May 17, 2023
@davidlougheed davidlougheed deleted the features/beacon-public-config-search branch May 23, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants